package com.example.luhenchang_pdf.pdfutils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.luhenchang_pdf.R;

import java.util.ArrayList;

public class PdfAdapter extends BaseAdapter {
    private ArrayList<PdfBean> mData;
    private Context context;
    public PdfAdapter(ArrayList<PdfBean> mData, Context context){
        this.mData=mData;
        this.context=context;
    }
    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(viewHolder==null){
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.ac_pdf_itme,null);
            viewHolder.pdf_img=convertView.findViewById(R.id.ac_item_img);
            viewHolder.pdf_text=convertView.findViewById(R.id.ac_item_tiltle);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.pdf_text.setText(mData.get(position).pdf_Title);
        viewHolder.pdf_img.setImageBitmap(mData.get(position).pdf_imagBitmap);
        return convertView;
    }
    public class ViewHolder{
        ImageView pdf_img;
        TextView pdf_text;
    }
}
